#include "Commands.h"

Command* CommandArray[32]; //should be big enough to hold all misc and low level commands, which is all we use
Command* mInvalid;

void SetupCommandArray()
{
	for (int i = 0; i < 32; ++i)
		CommandArray[i] = NULL;
	CommandArray[Connect] = new CommandConnect();
	CommandArray[Disconnect] = new CommandDisconnect();
	CommandArray[Wake] = new CommandWake();
	CommandArray[Sleep] = new CommandSleep();
	CommandArray[FeedWatchdog] = new CommandFeedWatchdog();
	CommandArray[EStop] = new CommandEStop();
	CommandArray[RequestResendMessage] = new CommandRequestResendMessage();
	CommandArray[ConfigPins] = new CommandConfigPins();
	CommandArray[OutDig] = new CommandOutDig();
	CommandArray[OutAnl] = new CommandOutAnl();
	CommandArray[InDigRequest] = new CommandInDigRequest();
	CommandArray[InDigStream] = new CommandInDigStream();
	CommandArray[InAnlRequest] = new CommandInAnlRequest();
	CommandArray[InAnlStream] = new CommandInAnlStream();
	mInvalid = new CommandInvalid();
}

void DeleteCommandArray()
{
	for(int i = 0; i < 32; i++)
		if(CommandArray[i] != NULL)
			delete CommandArray[i];
	delete mInvalid;
}

Command* GetCommand(int commandType)
{
	if(commandType >= 32)
	{
		return mInvalid;
	}
	else
	{
		if(CommandArray[commandType] == NULL)
		{
			return mInvalid;
		}
		return CommandArray[commandType];
	}
}
